//
//  ZHFPlayingView.m
//  GoTraveling
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "ZHFPlayingView.h"

@implementation ZHFPlayingView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}


- (void)createSubView{
    //音乐图片(中间的那个大图)
    self.musicImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width / 8, self.frame.size.height / 6, self.frame.size.width / 8 * 6, self.frame.size.width / 8 * 6)];
    //    self.musicImage.backgroundColor = [UIColor cyanColor];
    [self addSubview:self.musicImage];
    
    //音乐标题
    self.musicTitle = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width / 8, 400 * ADAPT_HEIGHT, self.frame.size.width / 8 * 6, 30 * ADAPT_HEIGHT)];
    
    //设置字体大小并居中
    self.musicTitle.font = [UIFont systemFontOfSize:22];
    self.musicTitle.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.musicTitle];
    
    //喜欢图标
    self.likeView = [[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width / 4, self.musicTitle.frame.origin.y + self.musicTitle.frame.size.height + self.frame.size.height / 20, 20, 20)];
    self.likeView.image = [UIImage imageNamed:@"cm2_rdi_btn_love_dis@2x.png"];
    [self addSubview:self.likeView];
    
    //喜欢人数
    self.likeNum = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width / 4 + self.likeView.frame.size.width + 2, self.musicTitle.frame.origin.y + self.musicTitle.frame.size.height + self.frame.size.height / 20, 40, 20)];
    self.likeNum.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.likeNum];
    
    //创建一个透明按钮覆盖喜欢图标与喜欢人数
    UIButton *likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    likeButton.frame = CGRectMake(self.likeView.frame.origin.x, self.likeView.frame.origin.y, self.likeView.frame.size.width + self.likeNum.frame.size.width, self.likeView.frame.size.height);
    [self addSubview:likeButton];
    [likeButton addTarget:self action:@selector(likeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //评论图标
    self.commentView = [[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width / 3 * 2, self.likeView.frame.origin.y, 20, 20)];
    self.commentView.image = [UIImage imageNamed:@"iconfont-pinglun副本.png"];
    [self addSubview:self.commentView];
    
    //评论人数
    self.commentNum = [[UILabel alloc]initWithFrame:CGRectMake(self.commentView.frame.origin.x + self.commentView.frame.size.width + 2, self.musicTitle.frame.origin.y + self.musicTitle.frame.size.height + self.frame.size.height / 20, 40, 20)];
    self.commentNum.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.commentNum];
    
    
    
    //创建一个透明按钮覆盖评论图标与评论人数
    UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    commentButton.frame = CGRectMake(self.commentView.frame.origin.x, self.commentView.frame.origin.y, self.commentView.frame.size.width + self.commentNum.frame.size.width, self.commentView.frame.size.height);
    [self addSubview:commentButton];
    [commentButton addTarget:self action:@selector(commentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //进度条
    self.musicSlider = [[UISlider alloc]initWithFrame:CGRectMake(self.frame.origin.x / 7 * 2, 500 * ADAPT_HEIGHT, self.frame.origin.x / 7 * 3, 10)];
    //创建一个image替换系统小球
    UIImage *slImage = [UIImage imageNamed:@"heikuai.png"];
    [self.musicSlider setThumbImage:slImage forState:UIControlStateNormal];
    //进度条左侧颜色
    self.musicSlider.minimumTrackTintColor = [UIColor colorWithRed:60/255.0 green:60/255.0 blue:60/255.0 alpha:1.0];
    //进度条右侧颜色
    self.musicSlider.maximumTrackTintColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
    [self addSubview:self.musicSlider];
    
    
    //音频剩余时长Label
    self.remainTime = [[UILabel alloc]initWithFrame:CGRectMake(self.musicSlider.frame.origin.x + self.musicSlider.frame.size.width + self.likeView.frame.size.width / 2, self.musicSlider.frame.origin.y - 5 * ADAPT_HEIGHT, self.likeNum.frame.size.width * 1.5, self.likeNum.frame.size.height)];
    self.remainTime.font = [UIFont systemFontOfSize:12];
    self.remainTime.textColor = [UIColor grayColor];
    self.remainTime.text = @"00 : 00";
    [self addSubview:self.remainTime];
    
}

#pragma mark - set

-(void)setPlayModel:(ZHFListPlayList *)playModel{
    
    [self.musicImage sd_setImageWithURL:playModel.imgUrl placeholderImage:nil];
    self.musicTitle.text = playModel.title;
    
}


- (void)likeButtonAction:(UIButton *)likeButtonAction{
    NSLog(@"喜欢");
    
}

- (void)commentButtonAction:(UIButton *)commentButtonAction{
    NSLog(@"评论");
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
